﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SQLite;
using Com.Toook.Common;

public partial class news_content : BaseShowPage
{
    protected string NewsTitle = string.Empty;
    protected string NewsContent = string.Empty;
    protected string SourceSite = string.Empty;
    protected string PubDate = string.Empty;
    protected string SourceUrl = string.Empty;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        InitNewsContent(Request["id"]);
    }
    private void InitNewsContent(string id)
    {
        int n;
        if(string.IsNullOrEmpty(id) || !int.TryParse(id, out n))
        {
            id = "1";
        }
        string siteId = "";
        string sql = "select title, link, content, pubDate, siteId " +
            " from RssNews where id=@id";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        cmd.Parameters.Add("@id", DbType.Int32).Value = id;
        SQLiteDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            if(reader.Read())
            {
                NewsContent = reader["content"].ToString();
                NewsTitle = reader["title"].ToString();
                siteId = reader["siteId"].ToString();
                PubDate = reader["pubDate"].ToString();
                SourceUrl = reader["link"].ToString();
                SourceSite = PageData.SelectNewsSiteRow(siteId)["SiteName"].ToString();
            }
            reader.Close();
            
        }
        catch(Exception exRead)
        {
            LogHelper.Log.Error("读取新闻详细内容出错。id=" + id, exRead);
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
        
    }
}
